<!--企业检修计划-->
<template>
    <Layout>
        <Form ref="queryForm" :model="dataToQuery" :label-width="120">
            <div v-if="!modelSelect">
                <Row class="query-form">
                    <Col span="8">
                        <FormItem label="二级集团：">
                            <two-level-org org-code v-model="dataToQuery.twoLevelOrgCode" />
                        </FormItem>
                    </Col>
                    <Col span="8">
                        <FormItem label="企业名称：" prop="companyId">
                            <company-select v-model="dataToQuery.companyName" style="width:100%" />
                            <!-- <cascader-dom class="query-form-el" ref='queryOrgCascader' @setOrgname='setQueryOrgName' :orgTree="true"
                                        :setCurrentName="{label:dataToQuery.companyName,value:dataToQuery.companyId}"></cascader-dom> -->
                        </FormItem>
                    </Col>
                    <Col span="8" v-if="!switchFlag">
                        <Button @click="switchQuery(true,88)" class="ivu-btn-switch" type="text">展开∨</Button>
                        <Button @click="reset" class="ivu-btn-reset">重置</Button>
                        <Button type="primary" class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
                    </Col>
                    <Col span="8" v-else>
                        <FormItem label="计划检修时间：" prop="month">
                            <DatePicker class="query-form-el" v-model="dataToQuery.monthRange" format="yyyy-MM-dd"
                                        type="daterange" placement="bottom-end" placeholder="请选择计划检修时间段"
                                        @on-change="(date) => onSelectFieldQueryDateRange(date, 'month')"></DatePicker>
                        </FormItem>
                    </Col>
                </Row>
                <Row v-show="switchFlag" class="query-form">
                    <Col span="8">
                        <FormItem label='类别：'>
                            <Select v-model="dataToQuery.cateList" multiple :max-tag-count="2">
                                <Option v-for="item in dictMap.categoriesList" :value="item.codingCodeId" :label="item.codingName" :key="item.codingCodeId">
                                    <span>{{ item.codingName }}</span>
                                    <span style="float:right;color:#ccc">{{ item.note }}</span>
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span="8">
                        <FormItem label='涉及的危险作业类别：'>
                            <Select v-model='dataToQuery.hazardousWorkItemArr' multiple placeholder="请选择危险作业项目" :max-tag-count="1" class='query-form-el'>
                                <Option v-for="item in dictMap.hazardousWorkItems" :value="item.codingCodeId"
                                        :key="item.codingCodeId">{{item.codingName }}
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span="8" v-if="!modelSelect">
                        <FormItem label='维修状态：' prop="repairStatus">
                            <Select v-model='dataToQuery.repairStatusArr' multiple :max-tag-count="2" :clearable="false">
                                <Option value="未开始">未开始</Option>
                                <Option value="维修中">维修中</Option>
                                <Option value="已完成">已完成</Option>
                            </Select>
                        </FormItem>
                    </Col>
                </Row>
                <Row v-show="switchFlag" class="query-form">
                    <Col span="8" offset="16">
                        <Button @click="switchQuery(false,88)" class="ivu-btn-switch" type="text">收起∧</Button>
                        <Button @click="reset" class="ivu-btn-reset">重置</Button>
                        <Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
                    </Col>
                </Row>
                <Row class="query-form">
                    <Col span="24">
                        <Button size="large" class="ivu-btn-add" icon="md-add" @click="addInfo">新增</Button>
                        <download-button :api="exportUrl" :post='true' :queryForm="dataToQuery" />
                        <!-- <Button type="primary" class="ivu-btn-add" icon="md-cloud-download" @click="exportList">导出</Button> -->
                    </Col>
                </Row>
            </div>
            <div v-else>
                <Row class="query-form">
                    <Col span="8">
                        <FormItem label="企业名称：" prop="companyId">
                            <Input class="query-form-el" readonly v-model="companyName"/>
                        </FormItem>
                    </Col>
                    <Col span="8">
                        <FormItem label="计划检修时间：" prop="month">
                            <DatePicker class="query-form-el" v-model="dataToQuery.monthRange" format="yyyy-MM-dd"
                                        type="daterange" placement="bottom-end" placeholder="请选择计划检修时间段"
                                        @on-change="(date) => onSelectFieldQueryDateRange(date, 'month')"></DatePicker>
                        </FormItem>
                    </Col>
                    <Col span="8" v-if="!switchFlag">
                        <Button @click="switchQuery(true)" class="ivu-btn-switch" type="text">展开∨</Button>
                        <Button @click="reset" class="ivu-btn-reset">重置</Button>
                        <Button type="primary" class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
                    </Col>
                    <Col span="8" v-else>
                        <FormItem label='类别：'>
                            <Select v-model="dataToQuery.cateList" multiple :max-tag-count="2">
                                <Option v-for="item in dictMap.categoriesList" :value="item.codingCodeId" :label="item.codingName" :key="item.codingCodeId">
                                    <span>{{ item.codingName }}</span>
                                    <span style="float:right;color:#ccc">{{ item.note }}</span>
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                </Row>
                <Row v-show="switchFlag" class="query-form">
                    <Col span="8">
                        <FormItem label='涉及的危险作业类别：'>
                            <Select v-model='dataToQuery.hazardousWorkItemArr' multiple placeholder="请选择危险作业项目" :max-tag-count="1" class='query-form-el'>
                                <Option v-for="item in dictMap.hazardousWorkItems" :value="item.codingCodeId"
                                        :key="item.codingCodeId">{{item.codingName }}
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span="8" offset="8">
                        <Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
                        <Button @click="reset" class="ivu-btn-reset">重置</Button>
                        <Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
                    </Col>
                </Row>
            </div>
        </Form>
        <Table ref='table' :height="tableHeight" no-data-text="没有查询到相关数据!" @on-selection-change='getSelectRows'
               @on-sort-change="sortChange" :show-summary="!modelSelect" :summary-method="(data) => this.gAmountTo(data,['teamNumbe','staffNumber'])" 
               :loading='pageStatus.loading'
               border :columns="columns1" :data="dataTable">
        </Table>
        <!--分页-->
        <Row style="margin-right:10px;">
            <Col span="24">
                <Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize"
                      @on-change="pageChange" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray"
                      show-total show-sizer show-elevator/>
                <!-- <Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange1" @on-page-size-change="pageSizeChange1" :page-size-opts="pageSizeArray" show-total show-sizer show-elevator /> -->
            </Col>
        </Row>
        <!--新增、修改、详情-->
        <Modal :title="mode == 'view' ?'企业检修计划基本信息详情':'企业检修计划基本信息'" :transfer=false :mask-closable="false"
               v-model="dialogShow" v-if="dataToView && dialogShow" :width=850 class-name='limit-height-dialog'>
            <Row>
                <Col span="24">
                    <Form ref="dialogForm" :class="mode === 'view'?'modal-view-detail':'modal-form'"
                          :show-message="false" :model="dataToView" :rules="mode === 'view'?{} :ruleCustom"
                          :label-position="mode === 'view'?'right':'top'" :label-width="mode === 'view'?140:null">
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='企业名称：' prop='companyId'>
                                    <div v-if="mode === 'view'">{{dataToView.companyName}}</div>
                                    <cascader-dom v-else ref='orgCascader' @setOrgInfo='setCompanyId' @setOrgname="setCompanyName" :orgTree="true" :currentOrgId="dataToView.companyId"
                                                  :setCurrentName="{label:dataToView.companyName,value:dataToView.companyId}"></cascader-dom>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='类别：' prop='categories'>
                                    <div v-if="mode === 'view'">{{dataToView.categoriesName}}</div>
                                    <Select v-else class='' placeholder="请选择类别" v-model='dataToView.categories'>
                                        <Option v-for="item in dictMap.categoriesList" :value="item.codingCodeId" :label="item.codingName" :key="item.codingCodeId">
                                            <span>{{ item.codingName }}</span>
                                            <span style="float:right;color:#ccc">{{ item.note }}</span>
                                        </Option>
                                    </Select>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='涉及的危险作业类别：' prop='hazardousWorkItemArr'>
                                    <div v-if="mode === 'view'">{{ dataToView.hazardousWorkItemName }}</div>
                                    <Select v-else v-model='dataToView.hazardousWorkItemArr' multiple placeholder="请选择危险作业项目" :max-tag-count="2" class='query-form-el'>
                                        <Option v-for="item in dictMap.hazardousWorkItems" :value="item.codingCodeId"
                                                :key="item.codingCodeId">{{item.codingName }}
                                        </Option>
                                    </Select>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='检维修内容名称：' prop='examinationName'>
                                    <div v-if="mode === 'view'">{{ dataToView.examinationName }}</div>
                                    <Input v-else class='' placeholder="请填写检维修内容名称" type='text' v-model='dataToView.examinationName'></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row v-if="dataToView.hazardousWorkItemArr.indexOf('EC-000002000000009') != -1" type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label='具体危险作业类别：' prop='otherHazardous'>
                                    <div v-if="mode === 'view'">{{ dataToView.otherHazardous }}</div>
                                    <Input v-else class='' placeholder="请填写具体危险作业类别" type='text' v-model='dataToView.otherHazardous'></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label='计划检修范围：' prop='examinationRange'>
                                    <div v-if="mode === 'view'">{{ dataToView.examinationRange }}</div>
                                    <Input v-else class='' placeholder="请填写计划检修范围" type='text' v-model='dataToView.examinationRange'></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='计划检修开始时间：' prop='projectStartSchedule'>
                                    <div v-if="mode === 'view'">{{ renderViewDate(dataToView.projectStartSchedule)}}</div>
                                    <DatePicker v-else class="w" placeholder="请选择计划检修开始时间" v-model='dataToView.projectStartSchedule'
                                                :options="{disabledDate(date) {return date && dataToView.projectEndSchedule && date.valueOf() > dataToView.projectEndSchedule;}}"></DatePicker>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='计划检修结束时间：' prop='projectEndSchedule'>
                                    <div v-if="mode === 'view'">{{ renderViewDate(dataToView.projectEndSchedule) }}</div>
                                    <DatePicker v-else class="w" placeholder="请选择计划检修结束时间" v-model='dataToView.projectEndSchedule'
                                                :options="{disabledDate(date) {return date && dataToView.projectStartSchedule && date.valueOf() < dataToView.projectStartSchedule;}}"></DatePicker>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='维修主管部门：' prop='maintenanceDepartment'>
                                    <div v-if="mode === 'view'">{{ dataToView.maintenanceDepartment }}</div>
                                    <Input v-else class='w' placeholder="请填写维修主管部门" type='text' v-model='dataToView.maintenanceDepartment'></Input>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='检维修工作负责人：' prop='maintenanceChargePerson'>
                                    <div v-if="mode === 'view'">{{ dataToView.maintenanceChargePerson }}</div>
                                    <Input v-else class='w' placeholder="请填写检维修工作负责人" type='text' v-model='dataToView.maintenanceChargePerson'></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='外协队伍数量：' prop='teamNumbe'>
                                    <div v-if="mode === 'view'">{{ dataToView.teamNumbe }}</div>
                                    <InputNumber v-else class='w' :min="0" placeholder="请填写外协队伍数量" disabled type='text' v-model='dataToView.teamNumbe'></InputNumber>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='检修人数：' prop='staffNumber'>
                                    <div v-if="mode === 'view'">{{ dataToView.staffNumber }}</div>
                                    <InputNumber v-else class='w' :min="0" placeholder="请填写检修人数" type='text' v-model='dataToView.staffNumber'></InputNumber>
                                </FormItem>
                            </Col>
                        </Row>
                        <!--<Row type="flex" justify="space-around" class="code-row-bg">-->
                            <!--<Col span="11">-->
                                <!--<FormItem label='维修状态：' prop="repairStatus">-->
                                    <!--<div v-if="mode === 'view'">{{ dataToView.repairStatus }}</div>-->
                                    <!--<Select v-else v-model='dataToView.repairStatus' :clearable="false" class='query-form-el'>-->
                                        <!--<Option value="未开始">未开始</Option>-->
                                        <!--<Option value="维修中">维修中</Option>-->
                                        <!--<Option value="已完成">已完成</Option>-->
                                    <!--</Select>-->
                                <!--</FormItem>-->
                            <!--</Col>-->
                            <!--<Col span="11">-->
                                <!--<FormItem label='检修完成时间：'>-->
                                    <!--<div v-if="mode === 'view'">{{ renderViewDate(dataToView.repairEndTime) }}</div>-->
                                    <!--<DatePicker v-else class="w" placeholder="请选择检修完成时间" v-model='dataToView.repairEndTime' :clearable="false"-->
                                                <!--:options="{disabledDate(date) {return date && date.valueOf() > new Date();}}"></DatePicker>-->
                                <!--</FormItem>-->
                            <!--</Col>-->
                        <!--</Row>-->
                        <Row>
                            <Col span="23" class="query-form" style="margin-left: 15px">
                                <Button v-if="mode !== 'view'" class="ivu-btn-add" icon="md-add" @click="itemModel=true,itemAdd=true;examConstructionItem={}">新增维修队伍</Button>
                                <Table highlight-row stripe border style="margin-top:10px;margin-bottom: 10px" :max-height="350" :columns="itemColumn"
                                       :data="dataToView.examConstructionItems">
                                </Table>
                            </Col>

                            <!--<Col span="11">-->
                            <!--<FormItem label='外协队伍名称：' prop='teamName'>-->
                            <!--<div v-if="mode === 'view'">{{ dataToView.teamName }}</div>-->
                            <!--<Input v-else class='w' placeholder="请填写外协队伍名称"  type='text' v-model='dataToView.teamName' readonly @on-focus="relatedPartiesModel=true"></Input>-->
                            <!--</FormItem>-->
                            <!--</Col>-->

                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem v-if="mode === 'view'" label="检修计划：">
                                    <div v-show="dataToView.idFiles.filter(t=>t.field==='1').length>0"
                                         v-for="(item,index) in dataToView.idFiles.filter(t=>t.field==='1')">
                                        <a @click="downloadFiles(item,index)"><span
                                                style="color: #3399ff;margin-left: 5px">{{ item.fileName }}</span></a>
                                        <Progress v-show="uploadListVisible[item.id]"
                                                  :percent="uploadListPercent[index]"></Progress>
                                    </div>
                                </FormItem>
                                <FormItem v-else label="检修计划：">
                                    <div>
                                        <Upload ref="upload"
                                                :before-upload="(file) => { beforeUpload1(file, 'id', 'examSelect/1') }"
                                                :show-upload-list="true"
                                                multiple
                                                type="drag"
                                                :action="fileUrl">
                                            <div style="padding: 10px">
                                                <Icon type="ios-cloud-upload" size="45" style="color: #3399ff"></Icon>
                                                <p>点击将文件拖拽到这里上传</p>
                                                <!--<span style="font-size:8px;color: #797a64">支持扩展名：.rar .zip .doc .docx .pdf...</span>-->
                                            </div>
                                        </Upload>
                                    </div>
                                    <div v-show="dataToView.idFiles.filter(t=>t.field==='1').length>0"
                                         v-for="(item,index) in dataToView.idFiles.filter(t=>t.field==='1')"
                                         :key='item'>
                                        <a @click="downloadFiles(item,index)">{{ item.fileName }}</a>
                                        <Button type="text" icon="md-trash"
                                                @click="removeFile1(item.id, 'id', 'examSelect/1')"
                                                style="margin-left: 5px;margin-bottom: 3px"/>
                                        <Progress v-show="uploadListVisible[item.id]"
                                                  :percent="uploadListPercent[index]"></Progress>
                                        <!--<Progress  v-show="filePercentVisible[index]" :percent="filePercent[index]"></Progress>-->
                                    </div>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem v-if="mode === 'view'" label="安全措施方案：">
                                    <div v-show="dataToView.idFiles.filter(t=>t.field==='2').length>0"
                                         v-for="(item,index) in dataToView.idFiles.filter(t=>t.field==='2')">
                                        <a @click="downloadFiles(item,index)"><span
                                                style="color: #3399ff;margin-left: 5px">{{ item.fileName }}</span></a>
                                        <Progress v-show="uploadListVisible[item.id]"
                                                  :percent="uploadListPercent[index]"></Progress>
                                    </div>
                                </FormItem>
                                <FormItem v-else label="安全措施方案：" prop="idFiles">
                                    <div>
                                        <Upload ref="upload"
                                                :before-upload="(file) => { beforeUpload1(file, 'id', 'examSelect/2') }"
                                                :show-upload-list="true"
                                                multiple
                                                type="drag"
                                                :action="fileUrl">
                                            <div style="padding: 10px">
                                                <Icon type="ios-cloud-upload" size="45" style="color: #3399ff"></Icon>
                                                <p>点击将文件拖拽到这里上传</p>
                                                <!--<span style="font-size:8px;color: #797a64">支持扩展名：.rar .zip .doc .docx .pdf...</span>-->
                                            </div>
                                        </Upload>
                                    </div>
                                    <div v-show="dataToView.idFiles.filter(t=>t.field==='2').length>0"
                                         v-for="(item,index) in dataToView.idFiles.filter(t=>t.field==='2')"
                                         :key='item'>
                                        <a @click="downloadFiles(item,index)">{{ item.fileName }}</a>
                                        <Button type="text" icon="md-trash"
                                                @click="removeFile1(item.id, 'id', 'examSelect/2')"
                                                style="margin-left: 5px;margin-bottom: 3px"/>
                                        <Progress v-show="uploadListVisible[item.id]"
                                                  :percent="uploadListPercent[index]"></Progress>
                                        <!--<Progress  v-show="filePercentVisible[index]" :percent="filePercent[index]"></Progress>-->
                                    </div>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem v-if="mode === 'view'" label="其他：">
                                    <div v-show="dataToView.idFiles.filter(t=>t.field==='3').length>0"
                                         v-for="(item,index) in dataToView.idFiles.filter(t=>t.field==='3')">
                                        <a @click="downloadFiles(item,index)"><span
                                                style="color: #3399ff;margin-left: 5px">{{ item.fileName }}</span></a>
                                        <Progress v-show="uploadListVisible[item.id]"
                                                  :percent="uploadListPercent[index]"></Progress>
                                    </div>
                                </FormItem>
                                <FormItem v-else label="其他：">
                                    <div>
                                        <Upload ref="upload"
                                                :before-upload="(file) => { beforeUpload1(file, 'id', 'examSelect/3') }"
                                                :show-upload-list="true"
                                                multiple
                                                type="drag"
                                                :action="fileUrl">
                                            <div style="padding: 10px">
                                                <Icon type="ios-cloud-upload" size="45" style="color: #3399ff"></Icon>
                                                <p>点击将文件拖拽到这里上传</p>
                                                <!--<span style="font-size:8px;color: #797a64">支持扩展名：.rar .zip .doc .docx .pdf...</span>-->
                                            </div>
                                        </Upload>
                                    </div>
                                    <div v-show="dataToView.idFiles.filter(t=>t.field==='3').length>0"
                                         v-for="(item,index) in dataToView.idFiles.filter(t=>t.field==='3')"
                                         :key='item'>
                                        <a @click="downloadFiles(item,index)">{{ item.fileName }}</a>
                                        <Button type="text" icon="md-trash"
                                                @click="removeFile1(item.id, 'id', 'examSelect/3')"
                                                style="margin-left: 5px;margin-bottom: 3px"/>
                                        <Progress v-show="uploadListVisible[item.id]"
                                                  :percent="uploadListPercent[index]"></Progress>
                                        <!--<Progress  v-show="filePercentVisible[index]" :percent="filePercent[index]"></Progress>-->
                                    </div>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label='备注：' prop='remarks'>
                                    <div v-if="mode === 'view'">{{dataToView.remarks}}</div>
                                    <Input v-else type='textarea' v-model='dataToView.remarks'></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='填报人：' prop='createUserName'>
                                    <div v-if="mode === 'view'">{{ dataToView.createUserName }}</div>
                                    <Input v-else class='query-form-el' placeholder="请填写填报人" type='text' readonly
                                           v-model='dataToView.createUserName'></Input>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='填报时间：' prop='createDate'>
                                    <div v-if="mode === 'view'">{{ renderViewDate(dataToView.createDate) }}</div>
                                    <DatePicker v-else class="query-form-el" placeholder="请选择填报时间" readonly
                                                v-model='dataToView.createDate'></DatePicker>
                                </FormItem>
                            </Col>
                        </Row>
                    </Form>
                </Col>
            </Row>
            <div slot="footer">
                <Button v-if="mode != 'view'" type="primary" class='ivu-btn-save' @click="submit('dialogForm')">确定</Button>
                <Button v-if="mode != 'view'" type="primary" class='ivu-btn-cancel' @click="handleCancel">取消</Button>
                <Button v-if="mode === 'view'" class='ivu-btn-save' @click="dialogShow=false">关闭</Button>
            </div>
        </Modal>

        <Modal :mask-closable="false" :transfer=false v-model="itemModel" :width=600 title="维修队伍"
               @on-cancel="itemModel=false,examConstructionItem={}">
            <Row>
                <Col span="24">
                    <Form ref="itemForm" :class="'modal-form'" :show-message="false" :model="examConstructionItem"
                          :rules="itemRuleCustom" label-position="top" >
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='维修项目：' prop='maintenanceName'>
                                    <Input class='' placeholder="请填写维修项目" type='text' v-model='examConstructionItem.maintenanceName'></Input>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='维修方：' prop='maintenanceTeam'>
                                    <Select v-model='examConstructionItem.maintenanceTeam' placeholder="请选择维修方" class='query-form-el'
                                            @on-change="(value) => {examConstructionItem.teamName=null,examConstructionItem.contractorId=null }">
                                        <Option value="1">企业内修</Option>
                                        <Option value="2">外包队伍</Option>
                                    </Select>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem :label="examConstructionItem.maintenanceTeam=='2'?'外协队伍名称：':'队伍名称：'" prop='teamName'>
                                    <Input class='' v-if="examConstructionItem.maintenanceTeam=='2'" placeholder="请填写外协队伍名称" type='text'
                                           readonly @on-focus="relatedPartiesModel=true" v-model='examConstructionItem.teamName'></Input>
                                    <Input class='' v-else-if="examConstructionItem.maintenanceTeam=='1'" placeholder="请填写队伍名称" type='text'
                                           v-model='examConstructionItem.teamName'></Input>
                                    <Input class='' v-else placeholder="请填写外协队伍名称" type='text' disabled v-model='examConstructionItem.teamName'></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='计划开工时间：' prop='planMaintenanceStart'>
                                    <DatePicker class="w" placeholder="请选择计划开工时间" v-model='examConstructionItem.planMaintenanceStart'
                                                :options="{disabledDate(date) {return date && examConstructionItem.planMaintenanceEnd && date.valueOf() > examConstructionItem.planMaintenanceEnd;}}"></DatePicker>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='计划完工时间：' prop='planMaintenanceEnd'>
                                    <DatePicker class="w" placeholder="请选择计划完工时间" v-model='examConstructionItem.planMaintenanceEnd'
                                                :options="{disabledDate(date) {return date && examConstructionItem.planMaintenanceStart && date.valueOf() < examConstructionItem.planMaintenanceStart;}}"></DatePicker>
                                </FormItem>
                            </Col>
                        </Row>
                    </Form>
                </Col>

                <Modal :mask-closable="false" :transfer=false footer-hide v-model="relatedPartiesModel" :width=900 title="相关方台账" @on-cancel="relatedPartiesModel=false">
                    <interested-parties-book v-if="relatedPartiesModel" v-show="relatedPartiesModel" :modelSelect="relatedPartiesModel"
                                             :companyId="dataToView.companyId" @getSelectModelData='getSelectCount'></interested-parties-book>
                </Modal>
            </Row>
            <div slot="footer">
                <Button type="primary" class='ivu-btn-save' @click="itemSubmit('itemForm')">确定</Button>
                <Button type="primary" class='ivu-btn-cancel' @click="itemModel=false,examConstructionItem={}">取消</Button>
                <!--<Button v-if="mode === 'view'" class='ivu-btn-save' @click="dialogShow=false">关闭</Button>-->
            </div>
        </Modal>


    </Layout>
</template>

<script>
    import {Api} from '@/api/index.js'
    import {sessionStorage} from '@/common/cacheUtils.js';
    import {formatDate} from '@/tools/index'
    var cascaderDom = () => import('@/components/cascader-dom.vue');
    import pageCommonFunction from '@/components/pageCommonFunction.js'
    import interestedPartiesBook from '../interestedPartiesManager/interestedPartiesBook'

    export default {
        props: ['companyId','companyName', 'modelSelect'],
        components: {cascaderDom, interestedPartiesBook},
        data() {
            return {
                ...this.createCommonDataField(),
                columns1: [
                    {
                        title: '序号', width: 80, fixed: 'left', align: 'center', render: (h, params) => {
                            if (params.row.id === '-1') return h('span', "汇总");
                            return h('span', (params.index - (this.modelSelect?0:1)) + (this.pagedata.currentPage - 1) * this.pagedata.pageSize + 1);
                        }
                    },
                    {key: 'companyName', title: '企业名称', align: 'center', minWidth: 200},
                    {key: 'repairStatus', title: '维修状态', minWidth: 100, align: 'center', },
                    {key: 'examinationName', title: '检维修内容名称', minWidth: 150, align: 'center', tooltip: true},
                    {key: 'examinationRange', title: '计划检修范围', minWidth: 150, align: 'center', tooltip: true},
                    {key: 'categoriesName', title: '类别', align: 'center', width: 120,},
                    {key:'hazardousWorkItemName',title: '涉及的危险作业类别',  align: 'center', minWidth: 120,  tooltip: true},
                    {key:'otherHazardous',title: '具体危险作业类别',  align: 'center', minWidth: 120,  tooltip: true},
                    {key: 'projectStartSchedule', title: '计划开始时间', sortable: "custom", minWidth: 100, align: 'center', render: this.renderCellDate},
                    {key: 'projectEndSchedule', title: '计划结束时间', sortable: "custom", minWidth: 100, align: 'center', render: this.renderCellDate},
                    // { key:'teamName',title: '外协队伍名称',minWidth: 110,  align: 'center' },
                    {key: 'teamNumbe', title: '外协队伍数量', minWidth: 110, align: 'center'},
                    {key: 'maintenanceDepartment', title: '维修主管部门', minWidth: 110, align: 'center'},
                    {key: 'maintenanceChargePerson', title: '检维修工作负责人', minWidth: 110, align: 'center'},
                    {key: 'staffNumber', title: '检修人数', minWidth: 90, align: 'center'},
                    {key: 'repairEndTime', title: '检修完成时间',sortable: "custom", minWidth: 100, align: 'center', render: this.renderCellDate},
                    {key: 'remarks', title: '备注', minWidth: 200, align: 'center', tooltip: true},
                    // !this.modelSelect?this.getActionColumns((params) => {return params.row.id === '-1'}) :
                    {title: '操作', key: 'action', fixed: 'right', width: this.modelSelect?80:180, align: 'center', render: (h, params) => {
                            if (this.modelSelect) {
                                return h('div', [
                                    h('A', {
                                        props: { type: 'primary', size: 'small' },
                                        style: { fontSize: '12px' },
                                        on: {click: () => {this.$emit('getSelectModelData',params.row);}}
                                    }, '选择'),
                                ])
                            }else {
                                if (params.row.id === '-1') {return;}
                                if (this.currentUser.loginId === this.Common.admin || this.currentUser.userId === params.row.createUserId  || this.currentUser.userRole.find(obj => obj.roleId == '73b38b37dff64392ba0ee7dd579bf293') != undefined || this.currentUser.userBeHandedOver.find(obj => obj == params.row.createUserId) != undefined) {
                                    return h('div', [
                                        h('A', {
                                            props: {type: 'primary', size: 'small'},
                                            style: {fontSize: '14px',},
                                            on: {
                                                click: () => {
                                                    this.viewData(params);
                                                }
                                            }
                                        }, '详情'),
                                        h('Divider', {props: {type: 'vertical'}}, ''),
                                        h('A', {
                                            props: {type: 'primary', size: 'small'},
                                            disabled: true,
                                            style: {fontSize: '14px'},
                                            on: {
                                                click: () => {
                                                    this.editData(params);
                                                }
                                            }
                                        }, '修改'),
                                        h('Divider', {props: {type: 'vertical'}}, ''),
                                        h('A', {
                                            props: {type: 'primary', size: 'small'},
                                            style: {
                                                fontSize: '14px',
                                                color: params.row.repairStatus ==='未开始'? 'red':'#d0d0d0' ,
                                                pointerEvents:  params.row.repairStatus ==='未开始' ? '' : 'none'
                                            },
                                            on: {
                                                click: () => {
                                                    this.deleteData(params);
                                                }
                                            }
                                        }, '删除')
                                    ]);
                                } else {
                                    return h('div', [
                                        h('A', {
                                            props: {type: 'primary', size: 'small'},
                                            style: {fontSize: '14px',},
                                            on: {
                                                click: () => {
                                                    this.viewData(params);
                                                }
                                            }
                                        }, '详情'),
                                        h('Divider', {props: {type: 'vertical'}}, ''),
                                        h('A', {
                                            props: {type: 'primary', size: 'small'},
                                            style: {fontSize: '14px', color: '#c5c8ce'}
                                        }, '修改'),
                                        h('Divider', {props: {type: 'vertical'}}, ''),
                                        h('A', {
                                            props: {type: 'primary', size: 'small'},
                                            style: {fontSize: '14px', color: '#c5c8ce'}
                                        }, '删除')
                                    ]);
                                }
                            }
                    }},
                ],
                ruleCustom: {
                    companyId: [{required: true, message: '请填写企业名称', trigger: 'change'}],
                    repairStatus: [{required: true, message: '请选择维修状态', trigger: 'change'}],
                    examinationRange: [{required: true, message: '请填写计划检修范围', trigger: 'change'}],
                    categories: [{required: true, message: '请选择类别', trigger: 'change'}],
                    projectStartSchedule: [{required: true, message: '请选择计划开始时间', trigger: 'change', type: 'date'}],
                    projectEndSchedule: [{required: true, message: '请选择计划结束时间', trigger: 'change', type: 'date'}],
                    examinationName: [ { required: true, message: '请填写检维修内容名称', trigger: 'change' } ],
                    maintenanceDepartment: [{required: true, message: '请填写维修主管部门', trigger: 'change'}],
                    maintenanceChargePerson: [{required: true, message: '请填写检维修工作负责人', trigger: 'change'}],
                    otherHazardous: [{required: true, message: '请填写具体危险作业类别', trigger: 'change'}],
                    hazardousWorkItemArr: [ {
                        validator: (rule, value, callback) => {
                            if (this.dataToView.hazardousWorkItemArr.length < 1) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    staffNumber: [{pattern: /^([0-9][0-9]*)?$/, required: true, message: '请填写检修人数,必须为数字', trigger: 'change, blur', type: 'number'}],
                    idFiles: [{
                        validator: (rule, value, callback) => {
                            if (this.dataToView.idFiles.filter(t=>t.field==='2').length < 1) {
                                callback('附件必须上传')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }]
                },
                tableHeight: 10,
                dictMap:{},
                examConstructionItem:{},
                itemModel:false,
                itemAdd:false,
                columns2: [
                    {title: '序号', width: 70, align: 'center', render: this.indexColumnsRender},
                    {key: 'maintenanceName', title: '维修项目', minWidth: 120, align: 'center',tooltip:true},
                    {key: 'maintenanceTeam', title: '维修方', width: 90, align: 'center',
                        render:(h, params)=>{return h('span',params.row.maintenanceTeam=='1'? "企业内修":params.row.maintenanceTeam=='2'?"外包队伍":'')} },
                    {key: 'teamName', title: '队伍名称', minWidth: 110, align: 'center',tooltip:true},
                    {key: 'planMaintenance', title: '计划维修时间', minWidth: 130, align: 'center',
                        render:(h, params)=>{return h('span',this.renderViewDate(params.row.planMaintenanceStart) +'至'+this.renderViewDate(params.row.planMaintenanceEnd))} },
                    {
                        title: '操作',
                        key: 'action',
                        fixed: 'right',
                        width: 110,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('A', {
                                    props: {type: 'primary', size: 'small'},
                                    style: {fontSize: '13px',},
                                    on: {
                                        click: () => {
                                            this.examConstructionItem = {...params.row}
                                            this.itemModel = true
                                            this.itemAdd = false
                                        }
                                    }
                                }, '修改'),
                                h('Divider', {props: {type: 'vertical'}}, ''),
                                h('A', {
                                    props: {type: 'primary', size: 'small'},
                                    style: {fontSize: '13px',color: 'red'},
                                    on: {
                                        click: () => {
                                            if (params.row.maintenanceTeam == '2') {
                                                this.dataToView.teamNumbe -=1
                                            } else if (params.row.maintenanceTeam == '1') {
                                                this.dataToView.teamNumbe1 -=1
                                            }
                                            this.dataToView.examConstructionItems.splice(params.index,1)
                                        }
                                    }
                                }, '删除'),
                            ])
                        }
                    }
                ],
                itemRuleCustom: {
                    maintenanceName: [{required: true, message: '请填写维修项目', trigger: 'change'}],
                    maintenanceTeam: [{required: true, message: '请选择维修方', trigger: 'change'}],
                    teamName: [{required: true, message: '请填写外协队伍名称', trigger: 'change'}],
                    planMaintenanceStart: [{required: true, message: '请选择计划开始时间', trigger: 'change', type: 'date'}],
                    planMaintenanceEnd: [{required: true, message: '请选择计划结束时间', trigger: 'change', type: 'date'}],
                },
                // api
                exportUrl: Api.exportExamRecords,
                queryUrl: Api.queryExamRecords,
                deleteUrl: Api.deleteExamRecords,
                updateUrl: Api.updateExamRecords,
                saveUrl: Api.saveExamRecords,
                buttonLoading: false,

                relatedPartiesModel: false,
            }
        },
        computed: {
            itemColumn() {
                const columns = [...this.columns2];
                const columns1 = []
                columns.forEach(item => {
                    if (this.mode !== 'view') {
                        columns1.push(item)
                    } else {
                        if (item.key !== 'action') {
                            columns1.push(item)
                        }
                    }
                })
                return columns1
            },
        },
        async mounted() {
            this.setTableHeight(193);
            await this.$http.get(Api.queryDictBycode+"EC-000001,EC-000002",{}).then((res)=>{
                this.dictMap = {
                    'categoriesList': res.data.data['EC-000001'],
                    'hazardousWorkItems': res.data.data['EC-000002']
                }
            }).catch(e => {
                this.$Message.error("数据字典获取失败")
            });
						this.dataToQuery.monthRange = [new Date().getFullYear()+'-01-01',new Date().getFullYear()+'-12-31']
						// this.dataToQuery.repairStatusArr = ['未开始','维修中']
						this.onSelectFieldQueryDateRange(this.dataToQuery.monthRange, 'month')
            this.query();
        },
        methods: {
            ...pageCommonFunction,
            itemSubmit(name){
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        this.$Modal.confirm({
                            title: '提示',
                            content: '<p>是否要提交？</p>',
                            onOk: () => {
                                let _this = this
                                _this.dataToView.examConstructionItems.splice()
                                if (_this.itemAdd) {
                                    _this.dataToView.examConstructionItems.push(_this.examConstructionItem)
                                } else {
                                    _this.dataToView.examConstructionItems[_this.examConstructionItem._index]= _this.examConstructionItem
                                }
                                _this.dataToView.teamNumbe = 0
																_this.dataToView.teamNumbe1 = 0
                                _this.dataToView.examConstructionItems.forEach(m=>{
                                    if (m.maintenanceTeam == '2') {
                                        _this.dataToView.teamNumbe +=1
                                    } else if (m.maintenanceTeam == '1') {
                                        _this.dataToView.teamNumbe1 +=1
                                    }
                                })
                                _this.itemModel = false
                            },
                            onCancel: () => {}
                        })
                    }else {
                        this.$Message.error('请填报完整!');
                    }
                })
            },
            getSelectCount(row) {
                this.$set(this.examConstructionItem, 'contractorId', row.bookId)
                this.examConstructionItem.teamName = row.contractorName;
                this.relatedPartiesModel = false;
            },
            deleteData(params) {
                this.deleteDateAjax(params);
            },
            exportList() {
                if (!this.dataToQuery.cateList || this.dataToQuery.cateList.length < 1) {
                    // this.dataToQuery.cateList = null
                    this.$delete(this.dataToQuery,'cateList')
                }
                if (!this.dataToQuery.hazardousWorkItemArr || this.dataToQuery.hazardousWorkItemArr.length < 1) {
                    // this.dataToQuery.cateList = null
                    this.$delete(this.dataToQuery,'hazardousWorkItemArr')
                }
                this.exportFormSubmit();
            },
            query() {
                if (this.companyId) {
                    this.dataToQuery.companyId = this.companyId
                    this.dataToQuery.modelSelectType = 1
                    this.dataToQuery.repairStatus = '未开始'
                }
                // if (!this.dataToQuery.cateList || this.dataToQuery.cateList.length < 1) {
                //     this.dataToQuery.cateList = null
                // }
				// if (this.dataToQuery.repairStatusArr != null && this.dataToQuery.repairStatusArr != undefined && this.dataToQuery.repairStatusArr.length < 1) {
				//     this.dataToQuery.repairStatusArr = null
				// }
                // if (!this.dataToQuery.hazardousWorkItemArr || this.dataToQuery.hazardousWorkItemArr.length < 1) {
                //     this.dataToQuery.hazardousWorkItemArr = null
                // }
                this.queryAjax();
            },
            submit(name) {
                // if (this.dataToView.staffNumber == '') this.dataToView.staffNumber = 0;
                if (this.dataToView.examConstructionItems.length < 1) {
                    this.$Message.warning('维修队伍至少填报一条');
                } else {
                    if (this.dataToView.hazardousWorkItemArr.length>0) {
                        if (this.dataToView.hazardousWorkItemArr.indexOf('EC-000002000000009') === -1) {
                            this.dataToView.otherHazardous = ''
                        }
                        this.dataToView.hazardousWorkItems = this.dataToView.hazardousWorkItemArr.join(',')
                    }
                    this.submitAjax(name);
                }
            },
            async beforeEditDialogOpen(data) {
                data.row.hazardousWorkItemArr = data.row.hazardousWorkItems?data.row.hazardousWorkItems.split(','):[]
            },
            async beforeViewDialogOpen(data) {
                data.row.hazardousWorkItemArr = data.row.hazardousWorkItems?data.row.hazardousWorkItems.split(','):[]
            },
            createEmptyDataToAdd() {
                return {
                    orgId: sessionStorage('userId').getObject('userId').companyId,
                    examinationRange: '',
                    teamNumbe: 0,
										teamNumbe1: 0,
                    staffNumber: 1,
                    id: this.get_uuid(),
                    idFiles: [],
                    examConstructionItems: [],
                    hazardousWorkItemArr:[],
                    repairStatus:'未开始'
                }
            },
            async afterDataToViewInit() {
                await this.getFiles1('id', 'examSelect');
            },

        }
    }
</script>

<style lang='css' scoped>
    @import '../../../index.css';
</style>
